@extends('admin.layout.layout', ['row' => @$page])

@section('contain')

    <div class="portlet">
        <div class="portlet-title">
            <div class="caption">
                <x-portlet-breadcrumb :page="$page"></x-portlet-breadcrumb>
            </div>
            <div class="actions">
                @if(session('admin.user_type')==1 )
                    <div class="item">
                        <a href="/{{ request()->path() }}/create" class="btn btn-primary">{{ ts('addnew') }}</a>
                    </div>
                @endif
            </div>
        </div>

        <div class="filter-wrapper">
            <form action="/{{ request()->path() }}/" class="form-inline filter-form">
                <div class=" input-group mb-3 custom-control-inline">
                    <input type="text" class="form-control s-input" name="value" value="{{ request()->input('value') }}" placeholder="{{ ts('ROLLSSEARCHTEXT') }}">
                </div>
                <div class="input-group mb-3 custom-control-inline">
                    <select name="allocated" class="form-control">
                        <option value="">{{ ts('select').' '.ts('status') }}</option>
                        <option value="1" {{ request()->input('allocated') == 1 ? 'selected' : '' }}>{{ ts('ALLOCATED') }}</option>
                        <option value="2" {{ request()->input('allocated') == 2 ? 'selected' : '' }}>{{ ts('UNALLOCATED') }}</option>
                    </select>
                </div>
                <x-flatpickr-date-range></x-flatpickr-date-range>

                <div class="mb-3">
                    <button class="btn btn-primary">{{ ts('SEARCH') }}</button>
                    <a href="/{{ request()->path() }}/" class="btn btn-warning">{{ ts('RESET') }}</a>
                </div>

            </form>
        </div>
        <div>
            <table class="table text-nowrap bt-table d-none">
                <thead>
                <tr class="order_column text-center">
                    <th class="text-center">{{ ts('SELECT') }}</th>
                    <th data-column="id" style="width: 80px">{{ ts('SEQUENCE') }}</th>
                    <th data-column="film_type_id" style="width: 150px">{{ ts('FILMTYPE') }}</th>
                    <th data-column="roll_number" style="width: 150px">{{ ts('rollnumber') }}</th>
                    @if(session('admin.user_type') == 1)
                        <th data-column="length" style="width: 150px">{{ ts('ROLLLENGTH') }}</th>
                    @endif
                    <th style="width: 150px">{{ ts('RESIDUELENGTH') }}</th>
                    <th style="width: 400px">{{ ts('status') }}</th>
                    <th data-column="date_entered" style="width: 400px">{{ ts('CREATEDAT') }}</th>
                    <th class="fixed-td" style="width:270px">
                        {{ ts('OPERATIONS') }}
                    </th>
                </tr>
                </thead>
                <tbody>
                @foreach($data as $k => $v)
                    <tr class="item-list">
                        <td class="text-center">
                            <input type="checkbox" class="roll_icheck icheck_input" name="ids[]" value="{{ $v->id }}">
                        </td>
                        <td>
                            <div class="truncated-3">{{ @$data->firstItem()+$k }}</div>
                        </td>
                        <td>
                            <div class="truncated-3">{{ ts('film_type_master.'.$v->film_type_id) }}</div>
                        </td>
                        <td>
                            <div class="truncated-3">{{ @$v->roll_number }}</div>
                        </td>
                        @if(session('admin.user_type') == 1)
                            <td>{{ @$v->length }}</td>
                        @endif
                        <td>
                            <div class="truncated-3 text-danger">{{ @$v->length - @$v->tlength }}</div>
                        </td>
                        <td>
                            @empty($v->roll_sales_id)
                                {{ ts('unallocated') }}
                            @else
                                {{ ts('allocated') }}
                            @endif
                        </td>
                        <td>
                            <div class="truncated-3">{{ @$v->created_at }}</div>
                        </td>
                        <td  class="fixed-td text-center" style="width:270px">
                            <a class="btn btn-success btn-sm" href='/{{ request()->path() }}/{{ $v->id }}'>{{ ts('VIEW') }}</a>

                            @if( getUserCanAssignLengthByRollId($v->id, session('admin.id')) > 0 )
                                <button type="button" class="btn btn-primary btn-sm" onclick="openRollsAssignByRollNumber({{ $v->roll_number }})">{{ ts('ASSIGN') }}</button>
                            @else
                                <button type="button" disabled="" class="btn btn-secondary btn-sm" onclick="openRollsAssignByRollNumber({{ $v->roll_number }})">{{ ts('ASSIGN') }}</button>
                            @endif
                            @if(session('admin.user_type')==1)
                                <a class="btn btn-warning btn-sm" href='/{{ request()->path() }}/{{ $v->id }}/edit'>{{ ts('edit') }}</a>
                                <span class="btn btn-danger btn-sm" onclick="handleDelete({{ $v->id }})">{{ ts('delete') }}</span>
                            @endif
                        </td>
                    </tr>
                @endforeach
                </tbody>
            </table>
            <div class="row my-3">
                <div class="col-auto">
                    <label style="cursor: pointer"><input type="checkbox" class="icheck_all" data-ele=".roll_icheck"><span class="ml-2">{{ ts('SELECTALL') }}</span></label>
                    <span class="btn btn-primary ml-3" onclick="deleteAlliCheck('.roll_icheck', '/admin/rolls/deletes')">{{ ts('delete') }}</span>
                </div>
                <div class="col">
                    {{ $data->appends(request()->input())->links() }}
                </div>
            </div>
        </div>

        <form class="modal fade modal-s1" id="rollsAssign">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title font-green">{{ ts('ASSIGNROLL') }}</h5>
                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                    </div>
                    <div class="modal-body">
                        <div class="form-item">
                            <div class="form-label" required="">{{ ts('rollnumber') }}</div>
                            <div class="form-input">
                                <input type="text" readonly name="roll_id" class="form-control">
                            </div>
                        </div>
                        <div class="alert alert-danger residue-length">可分配长度：<b></b> cm</div>
                        {{--<div class="form-item">
                            <div class="form-label" required="">{{ ts('PICKCATEGORY') }}</div>
                            <div class="form-input">
                                <div class="input-group custom-control-inline">
                                    <select name="category_id" onchange="getRollsAssignUsers(this.value)" class="form-control">
                                        <option value="">{{ ts('SELECT') }}</option>
                                        <option value="2">{{ ts('DISTRIBUTOR') }}</option>
                                        <option value="3">{{ ts('DEALER') }}</option>
                                        <option value="1">{{ ts('PRECUT') }}</option>
                                    </select>
                                </div>
                            </div>
                        </div>--}}
                        <div class="form-item">
                            <div class="form-label" required="">{{ ts('assigntouser') }}</div>
                            <div class="form-input">
                                <select class="form-control" name="user_id">
                                    @if(session('admin.user_type')==1)
                                        @foreach(\App\Models\Admin::where('user_type', 2)->where('status', 1)->get() as $v)
                                            <option value="{{ $v->id }}">{{ $v->abbr ?: $v->company_name }}</option>
                                        @endforeach
                                    @else
                                        <option value="{{ session('admin.id') }}">{{ ts('self') }}</option>
                                        @foreach(\App\Models\Admin::where('creator_id', session('admin.id'))->where('status', 1)->get() as $v)
                                            <option value="{{ $v->id }}">{{ $v->abbr ?: $v->company_name }}</option>
                                        @endforeach
                                    @endif
                                    {{--<option value="">{{ ts('USERS') }}</option>
                                    @if(session('admin.user_type')==1)
                                        @foreach(\App\Models\Admin::where('user_type', 2)->get(['id', 'abbr', 'company_name']) as $a)
                                            <option value="{{ @$a->id }}">{{ @$a->abbr ?: @$a->company_name }}</option>
                                        @endforeach
                                    @else
                                        @foreach(\App\Models\Admin::where('creator_id', session('admin.id'))->get(['id', 'abbr']) as $a)
                                            <option value="{{ @$a->id }}">{{ @$a->abbr ?: @$a->company_name }}</option>
                                        @endforeach
                                    @endif--}}
                                </select>
                            </div>
                        </div>
                        <div class="form-item">
                            <div class="form-label" required="">{{ ts('length') }}</div>
                            <div class="form-input">
                                <div class="input-group custom-control-inline">
                                    <div class="input-group-prepend">
                                        <label class="input-group-text">
                                            <input type="checkbox" class="icheck_input" name="all_length" value="1">
                                            <span class="ml-1">全部</span>
                                        </label>
                                    </div>
                                    <input type="number" class="form-control" name="length">
                                    <div class="input-group-prepend">
                                        <input type="checkbox" class="form-control">
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="py-3 text-center">
                            <button type="button" class="btn btn-primary" onclick="handleRollsAssign()">{{ ts('assign') }}</button>
                        </div>
                    </div>
                </div>
            </div>
        </form>

    </div>


@endsection

@section('script')
    <script>
        $('.table.bt-table').bootstrapTable({
            /*fixedColumns: true,
            fixedNumber: 1,
            fixedRightNumber: 1,*/
            showColumns: true,
            height:thh,
        })
    </script>
@endsection